package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.module.entity.CityInfo;
import com.atguigu.lease.module.entity.DistrictInfo;
import com.atguigu.lease.module.entity.ProvinceInfo;
import com.atguigu.lease.web.admin.service.CityInfoService;
import com.atguigu.lease.web.admin.service.DistrictInfoService;
import com.atguigu.lease.web.admin.service.ProvinceInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/region")
@Tag(name = "地区信息管理",description = "regionInfoController")
public class RegionInfoController {
    @Autowired
    private ProvinceInfoService provinceInfoService;

    @Autowired
    private CityInfoService cityInfoService;

    @Autowired
    private DistrictInfoService districtInfoService;

    @GetMapping("province/list")
    @Operation(summary = "查询省份列表")
    public Result<List<ProvinceInfo>> getPrivinceList(){
        return Result.ok(provinceInfoService.list());
    }


    @GetMapping("city/listByProvinceId")
    @Operation(summary = "根据省份查询城市列表")
    public Result<List<CityInfo>> getCityInfoListByProvinceId(@RequestParam Long id){
        return Result.ok(cityInfoService.list(new LambdaQueryWrapper<CityInfo>().eq(CityInfo::getProvinceId,id)));
    }

    @GetMapping("district/listByCityId")
    @Operation(summary = "根据城市id查询区域列表")
    public Result<List<DistrictInfo>> getDistrictInfoListByCityId(@RequestParam Long id){
        LambdaQueryWrapper<DistrictInfo>lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DistrictInfo::getCityId,id);
        return Result.ok(districtInfoService.list(lambdaQueryWrapper));
    }



}
